package com.fr.report.cellElement.core;

import com.fr.base.FRContext;
import com.fr.base.core.list.IntList;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.report.script.Calculator;
import java.util.logging.Level;
import java.util.logging.Logger;

public class IndexGrouper extends RecordGrouper
{
  private int index;

  public int getIndex()
  {
    return this.index;
  }

  public void setIndex(int paramInt)
  {
    this.index = paramInt;
  }

  public Group[] group(TableData paramTableData, int paramInt, int[] paramArrayOfInt, Calculator paramCalculator)
  {
    if (paramInt == -1)
      return super.group(paramTableData, paramInt, paramArrayOfInt, paramCalculator);
    if (paramArrayOfInt == null)
      try
      {
        paramArrayOfInt = IntList.range(paramTableData.getRowCount());
      }
      catch (TableDataException localTableDataException1)
      {
        FRContext.getLogger().log(Level.WARNING, localTableDataException1.getMessage(), localTableDataException1);
      }
    Object localObject = null;
    int i = 0;
    if ((this.index >= 0) && (this.index < paramArrayOfInt.length))
    {
      i = paramArrayOfInt[this.index];
      try
      {
        localObject = paramTableData.getValueAt(i, paramInt);
      }
      catch (TableDataException localTableDataException2)
      {
        FRContext.getLogger().log(Level.WARNING, localTableDataException2.getMessage(), localTableDataException2);
      }
    }
    return new Group[] { new Group(localObject, new int[] { i }) };
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && ("Attr".equals(paramXMLableReader.getTagName())))
    {
      String str;
      if ((str = paramXMLableReader.getAttr("index")) != null)
        setIndex(Integer.parseInt(str));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Attr").attr("index", this.index).end();
  }
}